Skip to content

Preserve PR diff scroll position#8618

Closed
raashish1601 wants to merge 1 commit intomicrosoft:mainfrom
raashish1601:fix/pr-tree-preserve-scroll-8206
Closed

Preserve PR diff scroll position#8618
raashish1601 wants to merge 1 commit intomicrosoft:mainfrom
raashish1601:fix/pr-tree-preserve-scroll-8206

Conversation

@raashish1601
Copy link
Copy Markdown

Fixes #8206.

Summary:

  • Preserve the visible range when re-selecting a PR diff from the tree.
  • Restore that range when the diff reopens so the scroll position stays stable.

Validation:

  • npm run compile:test
  • npm run compile:node
  • npx eslint src/commands.ts src/view/treeNodes/fileChangeNode.ts src/test/view/fileChangeNode.test.ts
  • npm test could not complete here because the Windows VS Code Insiders binary rejected the extension-host CLI flags in this environment.

Manual risk:

  • The fix is validated by compile/lint coverage, but a quick repro in VS Code Insiders is still the best final confirmation for the extension-host behavior.

import { FileChangeModel, GitFileChangeModel, InMemFileChangeModel, RemoteFileChangeModel } from '../fileChangeModel';
import { TreeNode, TreeNodeParent } from './treeNode';

const pullRequestDiffViewStates = new Map<string, vscode.Range>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid adding globals like this.

this.changeModel.status,
);
this.command = {
command: 'pr.openDiffView',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should continue to use the openDiffCommand. Maybe VS Code core's diff editor could instead be better about remembering the scroll position.

@alexr00
Copy link
Copy Markdown
Member

alexr00 commented Apr 1, 2026

Thank you for the PR, but I think this would be better solved by VS Code's diff editor better remembering scroll position.

@alexr00 alexr00 closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selecting an already opened file in the Pull Request pane resets the scroll position

2 participants